package test07.demo2;

import java.util.Random;

public class Thief {
    private Random random = new Random();

    // 小偷偷盗
    void steal(Thedoor thedoor) {
        System.out.println("小偷偷盗中...");
        boolean success = random.nextBoolean();
        if (success) {
            System.out.println("小偷偷盗成功！");
            return;
        }
        // 如果门是防盗门，则触发警报
        if (thedoor instanceof Steal) {
            ((Steal) thedoor).steal();
            System.out.println("小偷偷盗失败！");
        } else {
            System.out.println("小偷偷盗成功！");
        }
    }}
